package leetcode.median;

import java.util.Deque;
import java.util.LinkedList;

/**
 * ClassName: $456_Find132pattern
 * Description:
 * date: 2022-02-15 15:41
 *
 * @author liyifan
 */
public class $456_Find132pattern {
    public boolean find132pattern(int[] nums) {
        int len = nums.length;
        Deque<Integer> stack = new LinkedList<>();
        stack.push(nums[len - 1]);
        int max = Integer.MIN_VALUE;

        for(int i = len - 2;i >= 0;i--){
            if (nums[i] < max) {
                return true;
            }
            while (!stack.isEmpty() && nums[i] > stack.peek())
                max = stack.pop();
            if (nums[i] > max)
                stack.push(nums[i]);
        }
        return false;
    }
}
